package com.syyo.gulimall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: wang
 * @date: 2021/3/9 11:56
 * @Description: es配置类
 */
@Configuration
public class GulimallElasticsearchConfig {


    public static final RequestOptions COMMON_OPTION;

    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
        COMMON_OPTION = builder.build();
    }


    /**
     * 注入es对象
     *
     * @return
     */
    @Bean
    public RestHighLevelClient esClient() {
        RestClientBuilder builder = RestClient.builder(new HttpHost("gulimall.com", 9200, "http"));
        RestHighLevelClient client = new RestHighLevelClient(builder);
        return client;
    }


}
